package com.oa.pm.controller;

import com.joneying.common.annotation.CommonController;
import com.joneying.common.web.response.Resp;
import com.oa.core.BaseController;
import com.oa.pm.dto.RegistrationListDTO;
import com.oa.pm.service.IRegistrationService;
import com.oa.pm.vo.RegistrationListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.text.ParseException;
import java.util.List;


@Api(description = "登记")
@RequestMapping("/registration")
@RestController
public class RegistrationController extends BaseController {

    @Autowired
    private IRegistrationService registrationService;

    @Description("查询")
    @ApiOperation(value = "查询")
    @CommonController
    @GetMapping("/list")
    public Resp<List<RegistrationListVO>> list(@Valid RegistrationListDTO registrationListDTO){
        return new Resp().success(registrationService.findRegistrationList(registrationListDTO));
    }

    @Description("查询今天我的打卡记录")
    @ApiOperation(value = "查询")
    @CommonController
    @GetMapping("/my")
    public Resp<RegistrationListVO> getMyRegistration(){
        return new Resp().success(registrationService.getMyRegistration(getLoginUserId()));
    }

    @Description("登记")
    @ApiOperation(value = "登记")
    @CommonController
    @PostMapping("")
    public Resp add(@ApiParam("签到地址") @RequestParam String address, @ApiParam("形式 1-内勤 2-外勤") @RequestParam Integer form) throws ParseException {
        return registrationService.add(getLoginUserId(), address, form);
    }
}
